import { create } from 'zustand';
import { Agent } from '../components/AgentManager';

// 定义 Agent 状态类型
interface AgentState {
  agents: Agent[];
  selectedAgent: Agent | null;

  // Agent setters
  setAgents: (agents: Agent[]) => void;
  addAgent: (agent: Agent) => void;
  removeAgent: (id: string) => void;
  setSelectedAgent: (agent: Agent | null) => void;
  updateAgent: (id: string, updates: Partial<Agent>) => void;
}

// 创建 Agent store
export const useAgentStore = create<AgentState>()((set) => ({
  agents: [],
  selectedAgent: null,

  // Agent setters
  setAgents: (agents) => set({ agents }),
  addAgent: (agent) => set((state) => ({
    agents: [...state.agents, agent]
  })),
  removeAgent: (id) => set((state) => ({
    agents: state.agents.filter(agent => agent.id !== id)
  })),
  setSelectedAgent: (agent) => set({ selectedAgent: agent }),
  updateAgent: (id, updates) => set((state) => ({
    agents: state.agents.map(agent =>
      agent.id === id ? { ...agent, ...updates } : agent
    )
  })),
}));
